package common.data.sms
{
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	public class SmsService extends RemoteObject
	{
		
		public var SendSmsHandle:Function;
		public var findWqSmsHHandle:Function;
		public var failHandle:Function;
		
		public function SmsService()
		{
			super("smsService");
			this.showBusyCursor = true;
			
			this.getOperation("sendSms").addEventListener(ResultEvent.RESULT,SendSmsResult,false,0,true);
			this.getOperation("sendSms").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("sendSmsForRead").addEventListener(ResultEvent.RESULT,SendSmsResult,false,0,true);
			this.getOperation("sendSmsForRead").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("findWqSmsH").addEventListener(ResultEvent.RESULT,findWqSmsHResult,false,0,true);
			this.getOperation("findWqSmsH").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
		}
		
		/********************************************************************************/
		//保存操作
		public function SendSms(array:ArrayCollection):void{
			this.getOperation("sendSms").send(array);
		}
		
		public function SendSmsForRead(array:ArrayCollection):void{
			this.getOperation("sendSmsForRead").send(array);
		}
		//保存操作
		public function findWqSmsH(startDate:String,endDate:String,staffIds:Array,type:String):void{
			this.getOperation("findWqSmsH").send(startDate,endDate,staffIds,type);
		}
		
		//保存回调
		private function SendSmsResult(e:ResultEvent):void{
			try{
				if(SendSmsHandle){
					SendSmsHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		//保存回调
		private function findWqSmsHResult(e:ResultEvent):void{
			try{
				if(findWqSmsHHandle){
					findWqSmsHHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		/************************************************************************************/
		//错误回调
		private function failCallBack(e:FaultEvent):void{
			//			if(failCallBack){
			//				failCallBack.apply();
			//			}
			trace(e.message+"");
		}
	}
}